package com.gree.scmservice.config;

import com.threadnew.tnmq.consumer.RocketMQConsumer;
import com.threadnew.tnmq.factory.MQFactory;
import com.threadnew.tnmq.producer.RocketMQProducer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.protocol.heartbeat.MessageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by 180686 on 2021/6/23 14:50
 */

@Configuration
public class ConsumerConfig {

    @Autowired
    private SaasConsumer saasConsumer;

    @Bean(name = "SaasProducer", initMethod = "start", destroyMethod = "shutdown")
    public RocketMQProducer createSaasProducer() throws MQClientException {
        RocketMQProducer consumer = MQFactory.createProducer("10.2.30.75:9000", "RC_SCM_SAAS_TALENT_PGROUP", "RC_SCM_SAAS_TALENT_TOPIC");
        return consumer;
    }

    @Bean(name = "ScmEmailConsumer", initMethod = "start", destroyMethod = "shutdown")
    public RocketMQConsumer createScmEmailConsumer() throws MQClientException {
        RocketMQConsumer consumer = MQFactory.createConsumer("10.2.30.75:9000", "RC_SCM_SAAS_TALENT_CGROUP", "RC_SCM_SAAS_TALENT_TOPIC", "*");
        consumer.registerConsumerMessageListener(saasConsumer);
        consumer.getDefaultMQPushConsumer().setMessageModel(MessageModel.BROADCASTING);
        return consumer;
    }


}